import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:speed_random/pages/home/rand_com/com_results/view.dart';
import 'package:speed_random/pages/home/rand_com/view_body.dart';
import 'package:speed_random/pages/home/rand_com/view_set.dart';
import 'package:speed_random/widgets/row_two_buttons.dart';

import 'logic.dart';
import 'state.dart';

class RandComPage extends StatefulWidget {


  const RandComPage({Key? key})
      : super(key: key);

  @override
  State<RandComPage> createState() => _RandComPageState();
}

class _RandComPageState extends State<RandComPage> {


  final RandComLogic logic = Get.put(RandComLogic());
  final RandComState state = Get.find<RandComLogic>().state;



  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Obx(()=>Text(state.randComArgs.value.title)),
        //backgroundColor: AppStyles.colorAppBarbg,
        actions: [
          IconButton(
            icon: const Icon(Icons.history),
            onPressed: () {
              Get.to(() => ComResultsPage(),arguments: Get.arguments); // 跳转到历史页面
            },
          ),
        ],
      ),
      body: Container(
   // color: AppStyles.colorAppBarbg, // 添加红色背景
    child:Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [

            Expanded(child:
            // 在这里新增一个遮罩层，用户可以滑动遮罩层。移开开。看到下面的结果。
            ViewBody(logic: logic, state: state),
            ),
// ... existing code ...
            const SizedBox(height: 10),

            // 显示随机数总和




            /*底部状态按钮*/

            Obx(()=>rowRunOrSetButtons(
              isRun:state.isRun.value ,
              isManualStop:state.isManualStop.value ,
              onGetRandomNumPressed:logic.runComFunStart,
              onSettingsPressed: () {
                // 导航到设置页面
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => SettingsPage(logic: logic, state: state),
                  ),
                );
                // showSettingsDialog(context);
              },
              onOkPressed: (){
                logic.generateRandomNumbersStop(0);
              },
              onStopPressed: (){
                logic.generateRandomNumbersStop(2);
              },
            ),),
            /*底部状态按钮*/
            const SizedBox(height: 16),
          ],
        ),
      )),
    );
  }



}


